package com.ssh.cp.service;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssh.cp.entity.FileClass;
import com.ssh.cp.idao.IFileClassDao;
import com.ssh.cp.idao.IFileDao;
import com.ssh.cp.idao.ILogDao;
import com.ssh.cp.idao.IUserDao;
import com.ssh.cp.iservice.IAdminService;

@Service(value="adminService")
@Transactional
public class AdminService implements IAdminService{
	@Autowired
	IFileClassDao fileClassDao;
	
	@Autowired
	IUserDao userDao;
	
	@Autowired
	IFileDao fileDao;
	
	@Autowired
	ILogDao logDao;
	
	@Override
	public void addFileClass(String classname) {
		// TODO Auto-generated method stub
		FileClass aclass=new FileClass();
		aclass.setClassname(classname);
		System.out.println(aclass.getClassname());
		fileClassDao.addClass(aclass);
		
	}

	@Override
	public void delClass(int userid, int classid) {
		// TODO Auto-generated method stub
		if(userDao.checkRole(userid))
			fileClassDao.delClass(classid);
	}

	@Override
	public void renameClass(int classid, String classname) {
		// TODO Auto-generated method stub
		FileClass aclass=new FileClass();
		aclass.setClassid(classid);
		aclass.setClassname(classname);
		fileClassDao.renameClass(aclass);
	}

	@Override
	public boolean forbidUser(int theuserid, int adminid, int forbid) {
		// TODO Auto-generated method stub
		
		
		if(userDao.checkRole(adminid)) {
			userDao.forbidUser(theuserid, forbid);
			return true;
		}
			
		else {
			return false;
		}
	}

	@Override
	public boolean delFile(int adminid, int fileid) {
		// TODO Auto-generated method stub
		if(userDao.checkRole(adminid)) {
			fileDao.delFile(fileid);
			return true;
		}else
		
		
		return false;
	}

	@Override
	public List<?> listLoginLog(int adminid,int start,int length) {
		// TODO Auto-generated method stub
		if(userDao.checkRole(adminid)) {
			return logDao.listLoginLog(start,length);
		}else
		
		return null;
	}

	@Override
	public int getLoginLogNum() {
		// TODO Auto-generated method stub
		return logDao.getLoginLogNum();
	}

}
